<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.cdisc.org/ns/odm/v1.2">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/submission">
		<xsl:element name="ODM" namespace="http://www.cdisc.org/ns/odm/v1.2">
			<xsl:attribute name="ODMVersion">1.2.1</xsl:attribute>
			<xsl:attribute name="FileOID">www.novartis.com/<xsl:value-of select="Study/@id"/>/<xsl:value-of select="@croid"/>/<xsl:value-of select="@fileidnum"/></xsl:attribute>
			<xsl:attribute name="FileType">Snapshot</xsl:attribute>
			<xsl:attribute name="Description">Autogenerated transfer file.</xsl:attribute>
			<xsl:attribute name="AsOfDateTime"><xsl:value-of select="@asofdatetime"/></xsl:attribute>
			<xsl:attribute name="CreationDateTime"><xsl:value-of select="@creationdatetime"/></xsl:attribute>
			<xsl:element name="ClinicalData">
				<xsl:attribute name="StudyOID">www.novartis.com/<xsl:value-of select="Study/@id"/></xsl:attribute>
				<xsl:attribute name="MetaDataVersionOID">1</xsl:attribute>
				<xsl:for-each select="Study/Subject">
					<xsl:element name="SubjectData">
						<xsl:attribute name="SubjectKey"><xsl:value-of select="@id"/></xsl:attribute>
						<xsl:for-each select="Visit">
							<xsl:element name="StudyEventData">
								<xsl:attribute name="StudyEventOID"><xsl:value-of select="@visitNumber"/></xsl:attribute>
								<xsl:attribute name="StudyEventRepeatKey"><xsl:value-of select="@repeatkey"/></xsl:attribute>
								<xsl:element name="FormData">
									<xsl:attribute name="FormOID">Context</xsl:attribute>
									<xsl:element name="ItemGroupData">
										<xsl:attribute name="ItemGroupOID">ContextIG</xsl:attribute>
										<xsl:if test="@visitNumber != ''">
											<xsl:element name="ItemData">
												<xsl:attribute name="ItemOID">VISIT</xsl:attribute>
												<xsl:attribute name="Value"><xsl:value-of select="@id"/></xsl:attribute>
											</xsl:element>
										</xsl:if>
										<xsl:element name="ItemData">
											<xsl:attribute name="ItemOID">EXT1N</xsl:attribute>
											<xsl:attribute name="Value"><xsl:value-of select="@extension"/></xsl:attribute>
										</xsl:element>
									</xsl:element>
								</xsl:element>
								<xsl:for-each select="Scan">
									<xsl:element name="FormData">
										<xsl:attribute name="FormOID">Scan.<xsl:value-of select="@id"/></xsl:attribute>
										<xsl:attribute name="FormRepeatKey"><xsl:value-of select="@repeatkey"/></xsl:attribute>
										<xsl:for-each select="ImageFile">
											<xsl:element name="ItemGroupData">
												<xsl:attribute name="ItemGroupOID">DicomImageFile</xsl:attribute>
												<xsl:element name="ItemData">
													<xsl:attribute name="ItemOID">href</xsl:attribute>
													<xsl:attribute name="Value"><xsl:value-of select="@name"/></xsl:attribute>
												</xsl:element>
												<xsl:element name="ItemData">
													<xsl:attribute name="ItemOID">sha1hash</xsl:attribute>
													<xsl:attribute name="Value"><xsl:value-of select="@sha1hash"/></xsl:attribute>
												</xsl:element>
											</xsl:element>
										</xsl:for-each>
									</xsl:element>
								</xsl:for-each>
							</xsl:element>
						</xsl:for-each>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:element>
	</xsl:template>
</xsl:transform>